package edu.xlh.travel.controller.admin;

import com.alibaba.fastjson.JSONArray;
import edu.xlh.travel.common.Result;
import edu.xlh.travel.pojo.Hotel;
import edu.xlh.travel.pojo.Scenic;
import edu.xlh.travel.service.HotelService;
import edu.xlh.travel.syslog.annontion.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;

@Controller
@RequestMapping("/hotel")
public class HotelController {

    @Autowired
    private HotelService hotelService;

    /*
    * to hotelList page
    * */
    @Log("跳转酒店列表页面")
    @RequestMapping("/hotelList")
    public String hotelList() {
        return "admin/hotelmanage/hotelList";
    }

    @Log("查询所有酒店")
    @RequestMapping("/findAllHotel")
    @ResponseBody
    public Result findAllHotel(int page, int limit , HttpSession session) {
        return hotelService.findAll(page , limit , session);
    }

    @Log("跳转酒店添加页面")
    @RequestMapping("/toHotelAddPage")
    public String toHotelAddPage(HttpSession session) { return "admin/hotelmanage/hotelAdd"; }

    /*
     * edit hotel
     * */
    @Log("编辑酒店")
    @RequestMapping("/edit/{id}")
    @ResponseBody
    public Result edit(@PathVariable("id")String id , @RequestBody Hotel hotel , HttpSession session) {
        return hotelService.edit(id , hotel , session);
    }

    /*
     * edit MaoShu
     * */
    @Log("编辑酒店描述")
    @RequestMapping("/editMiaoShu/{id}")
    @ResponseBody
    public Result editMiaoShu(@PathVariable("id")String id , @RequestBody Hotel hotel , HttpSession session) {
        return hotelService.editMiaoShu(id , hotel , session);
    }
    /*
     * delete scenic by id
     * */
    @Log("根据id删除酒店")
    @RequestMapping("/deleteById/{id}")
    @ResponseBody
    public Result deleteById(@PathVariable("id") String id , @RequestBody HashMap hashMap , HttpSession session) {
        return hotelService.deleteById(id , hashMap , session);
    }

    /*
    * add Hotel
    * */
    @Log("添加酒店")
    @RequestMapping("/addHotel")
    @ResponseBody
    public Result addHotel(@RequestBody Hotel hotel , HttpSession session) {
        return hotelService.addHotel(hotel , session);
    }

    /*
     *
     * batch delete
     *  */
    @Log("批量删除酒店")
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Result batchDelete(@RequestBody JSONArray jsonArray , HttpSession session) {
        return hotelService.batchDelete(jsonArray ,session);
    }

    /*
     * query hotel by condition
     * */
    @Log("条件模糊查询酒店")
    @RequestMapping("/QueryHotelByCondition")
    @ResponseBody
    public Result  QueryHotelByCondition(Integer page, Integer limit, Hotel hotel , HttpSession session) throws IOException {
        return hotelService.QueryHotelByCondition(page , limit ,hotel , session);
    }

}
